<template>
<div class="js_dialog" id="dataDay" style="opacity: 0; display: none;">
    <div class="weui-mask"></div>
    <div class="weui-dialog">
        <!-- <div class="weui-dialog__hd"><strong class="weui-dialog__title">弹窗标题</strong></div> -->
        <div class="weui-dialog__bd">
            <div @click="onselect" class="sign_equal" id="sign_cal">

                <div class="sign_row"><div class="td_0 calendar_record">1</div><div class="td_1 calendar_record">2</div><div class="td_2 calendar_record">3</div><div class="td_3 calendar_record">4</div><div class="td_4 calendar_record">5</div><div class="td_5 calendar_record">6</div><div class="td_6 calendar_record">7</div></div>
                <div class="sign_row"><div class="td_0 calendar_record">8</div><div class="td_1 calendar_record">9</div><div class="td_2">10</div><div class="td_3">11</div><div class="td_4">12</div><div class="td_5 calendar_record">13</div><div class="td_6">14</div></div>
                <div class="sign_row"><div class="td_0 calendar_record">15</div><div class="td_1">16</div><div class="td_2">17</div><div class="td_3">18</div><div class="td_4 calendar_record">19</div><div class="td_5 calendar_record">20</div><div class="td_6 calendar_record">21</div></div>
                <div class="sign_row"><div class="td_0 calendar_record">22</div><div class="td_1 calendar_record">23</div><div class="td_2 calendar_record">24</div><div class="td_3 calendar_record">25</div><div class="td_4 calendar_record">26</div><div class="td_5 calendar_record">27</div><div class="td_6 calendar_record">28</div></div>
            </div>
        </div>
        <div class="weui-dialog__ft">
        <a @click="selectDate" href="javascript:;" class="weui-dialog__btn primary">确定</a>
        </div>
    </div>
</div>
</template>

<script>
export default  {
    name: 'DateDay',  // 组件名称
    data () {  // 数据
        return {
          msg: 'DateDay'
        }
    },
    methods:{ // 自定义方法，可对data进行处理
        onselect:function  () {
            console.log("onselect");
            console.dir(event.target)
            $(".sign_equal .on").removeClass("on");
            $(event.target).addClass("on");
        },
        selectDate:function  () {
            var selectId = this.$store.state.srDateId;
            $("#"+selectId).text($(".sign_equal .on").text());
            if(selectId == "statementDate"){
                this.$store.state.statementDate = $(".sign_equal .on").text();
                this.$store.commit('accountLoanDaysFunc');
                this.$store.commit('accountRepaymentAmountFunc')
            }else{
                this.$store.state.accountreMonthpaymentDate = $(".sign_equal .on").text();
            }
            this.countRepayDate();
            $(this.$el).attr("style","opacity: 0; display: none;");
        },
        countRepayDate(){
            //statementDate 账单日 //信用还款日
            if(this.$store.state.statementDate == "" || this.$store.state.accountreMonthpaymentDate == ""){
                return;
            }
            var nowDate = this.$store.state.nowDate;
            var addMonth = 2;
            if(nowDate.getDate()<=parseInt(this.$store.state.statementDate)){
                if(parseInt(this.$store.state.accountreMonthpaymentDate) <parseInt(this.$store.state.statementDate)){
                    addMonth = 2;
                }else{
                    addMonth = 1;
                }
            }else{
                if(parseInt(this.$store.state.accountreMonthpaymentDate) <parseInt(this.$store.state.statementDate)){
                    addMonth = 3;
                }else{
                    addMonth = 2;
                }
            }
            /*if(nowDate.getDate()>parseInt(this.$store.state.statementDate) && parseInt(this.$store.state.accountreMonthpaymentDate) <parseInt(this.$store.state.statementDate)){ // 出帐日子 还款日前  且 借款日子在出帐日前
                 addMonth = 3;
              }else{ // 出帐日子 还款日前  且 借款日子在出帐日后
                  this.$store.state.accountRepaymentDate = nowDate.getFullYear() + "-" + (nowDate.getMonth()+2) + "-" + this.$store.state.accountreMonthpaymentDate;
              }*/
          var hjdate = new Date(nowDate);
          hjdate.setMonth(nowDate.getMonth()+addMonth);
          hjdate.setDate(this.$store.state.accountreMonthpaymentDate);
          var theMonth =hjdate.getMonth()+1;
          if(theMonth<10){
            theMonth = "0" + theMonth;
          }
          var rmDate = hjdate.getDate();;
          if(rmDate<10){
            rmDate = "0" + rmDate;
          }
          this.$store.state.accountRepaymentDate = hjdate.getFullYear() + "-" + theMonth + "-" + rmDate;
          this.computeLoanDays();
          this.$store.commit('changeNoToinfo')
        },
        computeLoanDays(){ // 计算帮你延客户还钱到申请的天数
            var milliseconds = new Date(this.$store.state.accountRepaymentDate.replace(/-/g, "/") + " 23:59:59") - this.$store.state.nowDate;
            var loanDays = Math.floor(milliseconds/1000/60/60/24);
            this.$store.state.loanDays = loanDays;
        }

    }
}
</script>

<style lang='scss' scoped>

.singer_r_img {
    display: block;
    line-height: 45px;
//    background: url(../assets/images/sing_week.gif) right 2px no-repeat;
    vertical-align: middle;
    margin-bottom: -10px;
    text-decoration: none;
}

.singer_r_img:hover {
    background-position: right -53px;
    text-decoration: none;
}

.singer_r_img span {
    margin-left: 14px;
    font-size: 16px;
    font-family: 'Hiragino Sans GB','Microsoft YaHei',sans-serif !important;
    font-weight: 700;
    color: #165379;
}

.singer_r_img.current {
//    background: url(../assets/images/sing_sing.gif) no-repeat 0 2px;
    border: 0;
    text-decoration: none;
}


.sign_succ_calendar_title {
    text-align: center;
    /*width: 398px;*/
    border-left: 1px solid #e3e3e3;
    border-right: 1px solid #e3e3e3;
    background: #fff;
}

.sign_main {
    /*width: 400px;*/
/**background-color: #FBFEFE;**/
    border-top: 1px solid #e3e3e3;
    font-family: "Microsoft YaHei",SimHei;
    display: block;
}

.calendar_month_span {
    display: inline;
    line-height: 40px;
    font-size: 16px;
    color: #656565;
    letter-spacing: 2px;
    font-weight: bold;
}

.sign_equal {
    display:table;
    border-collapse:separate;
    width: 100%;
}

.sign_row {
    display:table-row;
}
.sign_row div {
    display:table-cell;
    width:14.3%;
    border-top: 1px solid #e3e3e3;
    /*border-bottom: 1px solid #e3e3e3;*/
    border-left: 1px solid #e3e3e3;
    height: 40px;
    text-align: center;
    line-height: 40px;
}
.sign_row .bold{
    font-weight: bold;
}
.sign_row div:last-child {
    border-right: 1px solid #e3e3e3;
}
.sign_equal .sign_row:last-child div{
    border-bottom: 1px solid #e3e3e3;
}
.sign_equal .on {
    background: url(../../assets/images/sign_have.gif) no-repeat center;
}

.sign_contener,.sign_contener:visited {
    line-height: 30px;
    background: #00a0e9;
    border: none;
    color: white;
    border-radius: 30px;
    padding: 0 10px;
    font-size: 16px;
}

.sign_contener:hover{
    background-color: red;
}


</style>
